package bite20220409;


import java.util.Objects;

class Man{
    private String name;
    private int age;

    public Man(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public String toString() {
        return "Man{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        //判断类型
        if (o == null || getClass() != o.getClass()) return false;
        Man man = (Man) o;
        return age == man.age && Objects.equals(name, man.name);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }
}

public class TestDemo2 {
    public static void main(String[] args) {
        Man man1 = new Man("whq",18);
        Man man2 = new Man("whq",18);

        System.out.println(man1.equals(man2));
    }

}
